package com.ruoyi.web.controller.library;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.library.domain.dto.page.LibBookPageDTO;
import com.ruoyi.library.domain.dto.update.LibBookUpdateStatusDTO;
import com.ruoyi.library.domain.vo.LibBookVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.library.domain.LibBook;
import com.ruoyi.library.service.ILibBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书馆-图书Controller
 *
 * @author xudengyu
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/library/book")
public class LibBookController extends BaseController
{
    @Resource
    private ILibBookService libBookService;

    @Log(title = "改变当前图书的状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeBookStatus")
    public AjaxResult changeBookStatus(@RequestBody LibBookUpdateStatusDTO libBookUpdateStatusDTO)
    {
        return success(libBookService.changeBookStatus(libBookUpdateStatusDTO));
    }

    /**
     * 查询图书馆-图书列表
     */
    @PreAuthorize("@ss.hasPermi('library:book:list')")
    @GetMapping("/page")
    public TableDataInfo page(LibBookPageDTO libBookPageDTO)
    {
        startPage();
        List<LibBookVO> list = libBookService.pageLibBookList(libBookPageDTO);
        return getDataTable(list);
    }


    /**
     * 查询图书馆-图书列表
     */
    @PreAuthorize("@ss.hasPermi('library:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibBook libBook)
    {
        startPage();
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        return getDataTable(list);
    }

    /**
     * 导出图书馆-图书列表
     */
    @PreAuthorize("@ss.hasPermi('library:book:export')")
    @Log(title = "图书馆-图书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibBook libBook)
    {
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        ExcelUtil<LibBook> util = new ExcelUtil<LibBook>(LibBook.class);
        util.exportExcel(response, list, "图书馆-图书数据");
    }

    /**
     * 获取图书馆-图书详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:book:query')")
    @GetMapping(value = "/{libBookId}")
    public AjaxResult getInfo(@PathVariable("libBookId") Long libBookId)
    {
        return success(libBookService.selectLibBookByLibBookId(libBookId));
    }

    /**
     * 新增图书馆-图书
     */
    @PreAuthorize("@ss.hasPermi('library:book:add')")
    @Log(title = "图书馆-图书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibBook libBook)
    {
        return toAjax(libBookService.insertLibBook(libBook));
    }

    /**
     * 修改图书馆-图书
     */
    @PreAuthorize("@ss.hasPermi('library:book:edit')")
    @Log(title = "图书馆-图书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibBook libBook)
    {
        return toAjax(libBookService.updateLibBook(libBook));
    }

    /**
     * 删除图书馆-图书
     */
    @PreAuthorize("@ss.hasPermi('library:book:remove')")
    @Log(title = "图书馆-图书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{libBookIds}")
    public AjaxResult remove(@PathVariable Long[] libBookIds)
    {
        return toAjax(libBookService.deleteLibBookByLibBookIds(libBookIds));
    }
}
